package com.jokerpan.project.controller;

import com.jokerpan.project.annotation.AccessLimit;
import com.jokerpan.project.entity.Menu;
import com.jokerpan.project.entity.Users;
import com.jokerpan.project.service.MenuService;
import com.jokerpan.project.service.UsersService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.security.Principal;

/**
 * @author jokerpan
 * @date 2022-4-23
 */
@RestController
@RequestMapping("menu")
@Api("菜单操作Api")
public class MenuController {

    @Resource
    public UsersService usersService;
    @Resource
    public MenuService menuService;

    /**
     * 获取页面菜单路由
     */
    @GetMapping("/getMenu")
    @AccessLimit(seconds = 6, maxCount = 5)
    @PreAuthorize("hasPermission('','user:list')")
    @ApiOperation("获取页面菜单路由")
    public Menu getMenu(Principal principal){
        String username = principal.getName();
        Users users = usersService.checkLoginName(username);
        Menu menu = menuService.getMenu(users.getRoleId());
        return menu;
    }


}
